package edu.pku.sei.modeler.uml.images;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;

/**
 * 
 * @author zsj created on 2008-3-9
 * @author YanYan Edited for all diagrams
 * @author fengchao fixed bugs concerning images
 * 
 */

public class ImageProvider {
	//added by fengchao
	static private Hashtable<String, Image> imageTable = new Hashtable<String, Image>();
	
	public static final String PROJECT_IMAGE = "Project.gif";

	public static final String PACKAGEINVIEW_IMAGE = "PackageInView.gif";

	public static final String UNKNOWN_IMAGE = "Unknown.gif";

	public static final String COMMENT_IMAGE = "Comment.gif";

	// For UML Use Case Diagram
	public static final String ACTOR_IMAGE = "Actor.gif";
	public static final String USECASE_IMAGE = "UseCase.gif";
	public static final String EXTEND_IMAGE = "Extend.gif";
	public static final String INCLUDE_IMAGE = "Include.gif";
	public static final String ASSOCIATION_IMAGE = "Association.gif";
	public static final String GENERALIZATION_IMAGE = "Generalization.gif";
	public static final String USECASEDIAGRAM_IMAGE = "UseCaseDiagram.gif";
	public static final String SUBJECT_IMAGE = "Subject.gif";

	// For UML Class Diagram
	public static final String CLASS_IMAGE = "Class.gif";
	public static final String PROPERTY_IMAGE = "Property.gif";
	public static final String OPERATION_IMAGE = "Operation.gif";
	public static final String INTERFACE_IMAGE = "Interface.gif";
	public static final String INSTANCESPECIFICATION_IMAGE = "InstanceSpecification.gif";
	public static final String PACKAGE_IMAGE = "Package.gif";
	public static final String DEPENDENCY_IMAGE = "Dependency.gif";
	public static final String INTERFACEREALIZATION_IMAGE = "InterfaceRealization.gif";
	public static final String REALIZATION_IMAGE = "Realization.gif";
	public static final String USAGE_IMAGE = "Usage.gif";
	public static final String PACKAGEIMPORT_IMAGE = "PackageImport.gif";
	public static final String PACKAGEMERGE_IMAGE = "PackageMerge.gif";
	public static final String CLASSDIAGRAM_IMAGE = "ClassDiagram.gif";

	// For UML Sequence Diagram
	public static final String SEQUENCEDIAGRAM_IMAGE = "SequenceDiagram.gif";
	public static final String INTERACTION_IMAGE = "Interaction.gif";
	public static final String LIFELINE_IMAGE = "Lifeline.gif";
	public static final String EXECUTIONOCCURRENCESPECIFICATION_IMAGE = "ExecutionOccurrence.gif";
	public static final String MESSAGE_IMAGE = "Message.gif";
	public static final String MESSAGE_SYNCHCALL_IMAGE = "Message_synchCall.gif";
	public static final String MESSAGE_ASYNCHCALL_IMAGE = "Message_asynchCall.gif";
	public static final String MESSAGE_REPLAY_IMAGE = "Message_reply.gif";
	public static final String DESTRUCTIONEVENT_IMAGE = "DestructionEvent.gif";
	public static final String STATEINVARIANT_IMAGE = "StateInvariant.gif";
	public static final String INTERACTIONOCCURRENCE_IMAGE = "InteractionOccurrence.gif";
	public static final String COMBINEDFRAGMENT_IMAGE = "CombinedFragment.gif";

	// For UML Activity Diagram
	public static final String ACTIVITYDIAGRAM_IAMGE = "ActivityDiagram.gif";
	public static final String ACTION_IMAGE = "Action.gif";
	public static final String CONTROLFLOW_IMAGE = "ControlFlow.gif";
	public static final String DECISIONNODE_IMAGE = "DecisionNode.gif";
	public static final String MERGENODE_IMAGE = "MergeNode.gif";
	public static final String FORKNODE_IMAGE = "ForkNode.gif";
	public static final String JOINNODE_IMAGE = "JoinNode.gif";
	public static final String INITIALNODE_IMAGE = "InitialNode.gif";
	public static final String ACTIVITYFINAL_IMAGE = "ActivityFinalNode.gif";
	public static final String ACTIVITY_IMAGE = "Activity.gif";
	public static final String FLOWFINAL_IMAGE = "FlowFinalNode.gif";
	public static final String DATASTORENODE_IMAGE = "DataStoreNode.gif";
	public static final String OBJECTFLOW_IMAGE = "ObjectFlow.gif";
	public static final String OBJECTNODE_IMAGE = "ObjectNode.gif";
	public static final String ACTIVITYPARTITION_IMAGE = "ActivityPartition.gif";
	
	// For UML Component Diagram
	public static final String COMPONENTDIAGRAM_IMAGE = "DiagramComponentDiagram.gif";
	public static final String COMPONENT_IMAGE = "Component.gif";
	public static final String ASSEMBLYCONNECTOR_IMAGE = "Connector_assembly.gif";
	public static final String DELEGATIONCONNECTOR_IMAGE = "Connector_delegation.gif";
	public static final String CONNECTOR_IMAGE = "Connector.gif";
	public static final String PORT_IMAGE = "Port.gif";
	public static final String USESINTERFACE_IMAGE = "required_interface.gif";
	public static final String IMPLEMENTSINTERFACE_IMAGE = "interface_provider.gif";
	public static final String COMPONENTINTERFACE_IMAGE = "Component_Interface.gif";
	
	//For UML StateMachine Diagram
	public static final String STATEDIAGRAM_IMAGE = "DiagramStateMachineDiagram.gif";
	public static final String STATE_IMAGE = "State.gif";
	public static final String STATEMACHINE_IMAGE = "StateMachine.gif";
	public static final String COMPLEXSTATE_IMAGE = "Complex_State.gif";
	public static final String TRANSION_IMAGE = "Transition.gif";
	public static final String FINALSTATE_IMAGE = "FinalState.gif";
	public static final String REGION_IMAGE = "Region.gif";
	public static final String PSEUDOSTATE_IMAGE = "Pseudostate.gif";
	public static final String INITIALPSEUDOSTATE_IMAGE = "Pseudostate_initial.gif";
	public static final String DEEPHISTORYPSEUDOSTATE_IMAGE = "Pseudostate_deepHistory.gif";
	public static final String SHALLOWHISTORYPSEUDOSTATE_IMAGE = "Pseudostate_shallowHistory.gif";
	public static final String JOINPSEUDOSTATE_IMAGE = "Pseudostate_join.gif";
	public static final String FORKPSEUDOSTATE_IMAGE = "Pseudostate_fork.gif";
	public static final String JUNCTIONPSEUDOSTATE_IMAGE = "Pseudostate_junction.gif";
	public static final String CHOICEPSEUDOSTATE_IMAGE = "Pseudostate_choice.gif";
	public static final String ENTRYPOINTPSEUDOSTATE_IMAGE = "Pseudostate_entryPoint.gif";
	public static final String EXITPOINTPSEUDOSTATE_IMAGE = "Pseudostate_exitPoint.gif";
	public static final String TERNIMATEPSEUDOSTATE_IMAGE = "Pseudostate_terminate.gif";
	
	//For UML Deployment Diagram
	public static final String DEPLOYMENTDIAGRAM_IMAGE = "Diagram_DeploymentDiagram.gif";
	public static final String ARTIFACT_IMAGE = "Artifact.gif";
	public static final String NODE_IMAGE = "Node.gif";
	public static final String DEVICE_IMAGE = "Device.gif";
	public static final String EXECUTIONENVIRONMENT_IMAGE = "ExecutionEnvironment.gif";
	public static final String DEPLOYMENTSPECIFICATION_IMAGE = "DeploymentSpecification.gif";
	public static final String DEPLOYMENT_IMAGE = "Deployment.gif";
	public static final String MANIFESTATION_IMAGE = "Manifestation.gif";
	public static final String COMMUNICATIONPATH_IMAGE = "CommunicationPath.gif";
	
	//TODO:
	//For UML Package Diagram
	public static final String PACKAGEDIAGRAM_IMAGE = "Diagram_Package.gif";
	
	//For UML CompositeStructure Diagram
	public static final String COMPOSITESTRUCTUREDIAGRAM_IMAGE = "Diagram_CompositeStructureDiagram.gif";
	public static final String STRUCTUREDCLASS_IMAGE = "StructuredClass.gif";
	
	//For UML InteractionOverview Diagram
	public static final String INTERACTIONOVERVIEWDIAGRAM_IMAGE = "Diagram_InteractionOverview.gif";
	
	//For UML Timing Diagram
	public static final String TIMINGDIAGRAM_IMAGE = "Diagram_Timing.gif";
	
	//For UML Communication Diagram
	public static final String COMMUNICATIONDIAGRAM_IMAGE = "Diagram_Communication.gif";
	
	// TODO: NEW ICONS
//	private static final Map<String, Image> stringToImage = new HashMap<String, Image>();
//
//	public static Image getImage(String key) {
//		Image img = (Image) stringToImage.get(key);
//		if (img == null) {
//			img = getImageDescriptor(key).createImage();
//			// cache the image
//			stringToImage.put(key, img);
//		}
//		return img;
//	}

	public static ImageDescriptor getImageDescriptor(String key) {
		return ImageDescriptor.createFromFile(ImageProvider.class, key);
	}
	//added by fengchao
	public static Image getImage(final String imageName) {
		Image img = imageTable.get(imageName);
		if (img != null) {
			return img;
		} else {
			ImageDescriptor imageDescriptor = ImageProvider
					.getImageDescriptor(imageName);
			img  = imageDescriptor.createImage();
			imageTable.put(imageName, img);
			return img;
		}
	}
}
